<?php 
class ControllerInformationForhandlen extends Controller {
	public function index() {  
    	$this->language->load('information/forhandlen');
        
		$this->document->title = $this->language->get('meta_title'); 
        $this->document->keywords = $this->config->get('config_meta_keywords');
        $this->document->description = $this->config->get('config_meta_description');
         
		$this->data['template'] = $this->config->get('config_template');     
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/forhandlen.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/information/forhandlen.tpl';
		} else {
			$this->template = 'default/template/information/information.tpl';
		}
		
		$this->load->model('catalog/information');
		//-- begin get information		
		$hvordan_handler_du_info = $this->model_catalog_information->getInformation(7);//-- Hvordan handler du        
		if ($hvordan_handler_du_info) { 						
            $short_desc = $this->shortDescription($hvordan_handler_du_info['description']);
            $link = HTTP_SERVER . 'index.php?route=information/information&information_id=' . $hvordan_handler_du_info['information_id'];
      		
            $this->data['hvordan_heading_title'] = $hvordan_handler_du_info['title'];       		            
			$this->data['hvordan_description'] = $short_desc['data'];
            $this->data['hvordan_link'] = $short_desc['break'] ? $link : '';         
    	}
    	
		$betaling_info = $this->model_catalog_information->getInformation(8);//-- Betaling & Finansiering
		if ($betaling_info) {  						
            $short_desc = $this->shortDescription($betaling_info['description']); 
            $link = HTTP_SERVER . 'index.php?route=information/information&information_id=' . $betaling_info['information_id'];
            
      		$this->data['betaling_heading_title'] = $betaling_info['title'];
      		$this->data['betaling_description'] = $short_desc['data'];
            $this->data['betaling_link'] = $short_desc['break'] ? $link : '';         
    	}
    	
		$levering_info = $this->model_catalog_information->getInformation(9);//-- Levering
		if ($levering_info) {      					
            $short_desc = $this->shortDescription($levering_info['description']); 
            $link = HTTP_SERVER . 'index.php?route=information/information&information_id=' . $levering_info['information_id'];
            	
      		$this->data['levering_heading_title'] = $levering_info['title'];
      		$this->data['levering_description'] = $short_desc['data'];
            $this->data['levering_link'] = $short_desc['break'] ? $link : ''; 
    	}
    	
		$support_info = $this->model_catalog_information->getInformation(10);//-- Support
		if ($support_info) { 	
            $short_desc = $this->shortDescription($support_info['description']); 
            $link = HTTP_SERVER . 'index.php?route=information/information&information_id=' . $support_info['information_id'];
            					
      		$this->data['support_heading_title'] = $support_info['title'];
            $this->data['support_description'] = $short_desc['data'];
            $this->data['support_link'] = $short_desc['break'] ? $link : ''; 
    	}
    	
		$hvad_info = $this->model_catalog_information->getInformation(11);//-- Hvad tilbyder havhøkeren
		if ($hvad_info) { 
            $short_desc = $this->shortDescription($hvad_info['description']); 
            $link = HTTP_SERVER . 'index.php?route=information/information&information_id=' . $hvad_info['information_id'];
                                 						
      		$this->data['hvad_heading_title'] = $hvad_info['title'];
      		$this->data['hvad_description'] = $short_desc['data'];
            $this->data['hvad_link'] = $short_desc['break'] ? $link : '';
    	}
    	
		$om_info = $this->model_catalog_information->getInformation(12);//-- Om os
		if ($om_info) {         
            $short_desc = $this->shortDescription($om_info['description']); 
            $link = HTTP_SERVER . 'index.php?route=information/information&information_id=' . $om_info['information_id'];
            						
      		$this->data['om_heading_title'] = $om_info['title'];
      		$this->data['om_description'] = $short_desc['data'];
            $this->data['om_link'] = $short_desc['break'] ? $link : '';
    	}
		//-- end get information
		
		$this->children = array(
				//'common/column_right',
				'common/footer',
				'common/column_left',
				'common/header',
				'module/services',
                'module/newsletter'
			);
		
	  	$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  	}
    
    private function shortDescription($content){  
        /* 
        if(stripos($content, '{READ_MORE}')){
            $temp = explode('{READ_MORE}', $content);
            $content = $temp[0];
            
            $data = explode('<p>', $content);
            foreach($data as &$item){
                if(!stripos('</p>', $item)){
                    $item .= '</p>';
                }
            }
            $data = implode('<p>', $data);
            
            $data = explode('<ul>', $data);
            foreach($data as &$item){
                if(!stripos('</ul>', $item)){
                    $item .= '</ul>';
                }
            }
            $data = implode('<ul>', $data);
            
            $data = explode('<li>', $data);
            foreach($data as &$item){
                if(!stripos('</li>', $item)){
                    $item .= '</li>';
                }
            }
            $data = implode('<li>', $data);
            
            $content = html_entity_decode($data);
            $break = true; 
        }
        else{     
            $content = strip_tags(html_entity_decode($content), '<a>');
            $break = mb_strlen($content, 'UTF-8') > 270;
            $content = $break ? (mb_substr($content, 0, 270, 'UTF-8') . '...') : $content; 
        }
        */
        
        /*
        $content1 = array(); 
        $content2 = array();         
        if(preg_match('@.*\{link.*\}(.*)\{.link\}@i', $content, $content1)){         
            if(preg_match('@\s\d+@i', $content1[0], $content2)){ 
                $href = '<a href="' . HTTP_SERVER . 'index.php?route=information/information&information_id=' . $content2[0] . '">' . $content1[1] . '</a>';
                $content = str_replace($content1[0], $href, $content);
            }
        }
        */
        
        $content = strip_tags(html_entity_decode($content), '<a>');
        $break = mb_strlen($content, 'UTF-8') > 160;
        $content = $break ? (mb_substr($content, 0, 160, 'UTF-8') . '...') : $content; 
        
        return array(
            'data'      => $content,
            'break'     => $break,
        );
    }
}
?>